package com.http;

import com.woke.method.MyApp;

import java.io.IOException;
import java.util.HashSet;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * <p>
 * 标题 ：
 * 备注： 设置 Cookie
 */
public class CookiesAddInterceptor implements Interceptor {
	@Override
	public Response intercept(Chain chai) throws IOException {
		Request.Builder builder = chai.request ().newBuilder ();
		HashSet<String> cookies = MyApp.newInstance ().readCookies ();
		if (cookies != null && cookies.size () > 0) {
			for (String cookie : cookies) {
				builder.addHeader ("Cookie", cookie);
			}
		}
		builder.addHeader ("User-Agent", "88chinapay");
		return chai.proceed (builder.build ());
	}
}
